package com.bawei.base.utils.mvvm

import androidx.lifecycle.ViewModel
import com.bawei.base.utils.ApiService.ApiService
import com.bawei.base.utils.RetrofitUtils
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

open class BaseViewModel : ViewModel() {

    var apiService : ApiService = RetrofitUtils.getRetrofit().create(ApiService::class.java)

    fun mapToBody(map:MutableMap<String,Any>) : RequestBody {
        val s = Gson().toJson(map)
        val body = RequestBody.create("application/json;charset=utf-8".toMediaTypeOrNull(), s)
        return body
    }

}